<template>
  <div class="blog-container">
    <!-- 顶部导航栏 -->
    <header class="blog-header">
      <div class="header-content">
        <div class="home-icon" @click="goToHome" title="返回主页">
            <i class="fas fa-home"></i>
        </div>
        <div class="logo">
          <i class="fas fa-laptop-code"></i>
          <span>TechBlog</span>
        </div>
        <div class="search-container">
          <i class="fas fa-search"></i>
          <input 
            type="text" 
            placeholder="搜索技术文章..." 
            v-model="searchQuery"
            @input="filterArticles"
          >
        </div>
      </div>
    </header>
    
    <!-- 主要内容区域 -->
    <main class="blog-main">
      <section class="hero">
        <h1>探索前沿技术，分享开发经验</h1>
        <p>在这里，您将发现关于Web开发、人工智能、云计算等领域的深度技术文章和实践经验分享</p>
      </section>
      
      <!-- 分类导航 -->
      <div class="categories">
        <button 
          v-for="category in categories" 
          :key="category.id"
          :class="['category-btn', { active: selectedCategory === category.id }]"
          @click="selectCategory(category.id)"
        >
          {{ category.name }}
        </button>
      </div>
      
      <!-- 博客文章列表 -->
      <div class="content">
        <div v-if="filteredArticles.length === 0" class="empty-state">
          <i class="fas fa-file-alt"></i>
          <h3>未找到相关文章</h3>
          <p>当前分类和搜索条件下没有找到匹配的文章，请尝试其他关键词或分类</p>
        </div>
        
        <div 
          v-for="article in filteredArticles" 
          :key="article.id" 
          class="blog-card"
        >
          <div class="card-image" :style="{ background: article.bgColor }">
            <i :class="article.icon"></i>
          </div>
          <div class="card-content">
            <span class="card-category">{{ getCategoryName(article.category) }}</span>
            <h3 class="card-title">{{ article.title }}</h3>
            <p class="card-excerpt">{{ article.excerpt }}</p>
            <div class="card-meta">
              <span><i class="far fa-calendar"></i> {{ article.date }}</span>
              <span><i class="far fa-user"></i> {{ article.author }}</span>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 统计信息 -->
      <div class="stats">
        <div class="stat-card">
          <i class="fas fa-file-alt"></i>
          <div class="number">{{ articles.length }}</div>
          <div class="label">技术文章</div>
        </div>
        <div class="stat-card">
          <i class="fas fa-tags"></i>
          <div class="number">{{ categories.length }}</div>
          <div class="label">技术分类</div>
        </div>
        <div class="stat-card">
          <i class="fas fa-users"></i>
          <div class="number">18,245</div>
          <div class="label">月访问量</div>
        </div>
      </div>
    </main>
    
    <!-- 页脚 -->
    <footer class="blog-footer">
      <p>© 2023 TechBlog - 专注于技术分享与交流 | 使用 Vue 3 构建</p>
    </footer>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const goToHome = () => {
    router.push('/')
}

const categories = ref([
{ id: 'all', name: '全部' },
{ id: 'web', name: '前端开发' },
{ id: 'backend', name: '后端技术' },
{ id: 'ai', name: '人工智能' },
{ id: 'cloud', name: '云计算' },
{ id: 'devops', name: 'DevOps' },
{ id: 'database', name: '数据库' }
])

// 当前选中的分类
const selectedCategory = ref('all')

// 搜索查询词
const searchQuery = ref('')

// 文章数据
const articles = ref([
{
    id: 1,
    title: 'Vue3 组合式 API 深度解析',
    excerpt: '本文深入探讨Vue3的组合式API，包括ref、reactive、watchEffect等核心概念的使用和最佳实践。',
    category: 'web',
    date: '2023-10-15',
    author: '张技术',
    icon: 'fab fa-vuejs',
    bgColor: 'linear-gradient(120deg, #42b883, #35495e)'
},
{
    id: 2,
    title: 'React性能优化完全指南',
    excerpt: '通过实际案例介绍React应用中常见的性能瓶颈及其解决方案，包括memoization、懒加载等技巧。',
    category: 'web',
    date: '2023-10-10',
    author: '李前端',
    icon: 'fab fa-react',
    bgColor: 'linear-gradient(120deg, #61dafb, #282c34)'
},
{
    id: 3,
    title: 'Node.js高并发解决方案',
    excerpt: '探讨Node.js在高并发场景下的性能优化策略，包括集群模式、负载均衡和异步处理技术。',
    category: 'backend',
    date: '2023-10-05',
    author: '王后端',
    icon: 'fab fa-node-js',
    bgColor: 'linear-gradient(120deg, #8cc84b, #3c873a)'
},
{
    id: 4,
    title: 'Docker容器化最佳实践',
    excerpt: '分享Docker容器化部署的行业最佳实践，包括镜像优化、安全配置和CI/CD集成方案。',
    category: 'devops',
    date: '2023-09-28',
    author: '赵运维',
    icon: 'fab fa-docker',
    bgColor: 'linear-gradient(120deg, #2496ed, #0db7ed)'
},
{
    id: 5,
    title: 'TensorFlow实战：图像识别',
    excerpt: '使用TensorFlow构建卷积神经网络实现高精度图像识别，包含数据预处理和模型调优技巧。',
    category: 'ai',
    date: '2023-09-20',
    author: '陈AI',
    icon: 'fas fa-robot',
    bgColor: 'linear-gradient(120deg, #ff6f00, #ffa000)'
},
{
    id: 6,
    title: 'AWS Lambda无服务架构实践',
    excerpt: '基于AWS Lambda构建无服务器应用的完整指南，涵盖事件驱动架构和成本优化策略。',
    category: 'cloud',
    date: '2023-09-15',
    author: '周云计算',
    icon: 'fas fa-cloud',
    bgColor: 'linear-gradient(120deg, #ff9900, #232f3e)'
},
{
    id: 7,
    title: 'MongoDB分片集群部署指南',
    excerpt: '详细讲解MongoDB分片集群的部署步骤和配置优化，解决大数据量存储和高并发访问问题。',
    category: 'database',
    date: '2023-09-10',
    author: '吴数据',
    icon: 'fas fa-database',
    bgColor: 'linear-gradient(120deg, #589636, #4db33d)'
},
{
    id: 8,
    title: '微服务架构设计模式',
    excerpt: '深入分析微服务架构中的常见设计模式，包括服务发现、熔断机制和分布式事务解决方案。',
    category: 'backend',
    date: '2023-09-05',
    author: '郑架构',
    icon: 'fas fa-network-wired',
    bgColor: 'linear-gradient(120deg, #6a1b9a, #9c27b0)'
}
])

// 获取分类名称
const getCategoryName = (categoryId) => {
const category = categories.value.find(cat => cat.id === categoryId)
return category ? category.name : '未知分类'
}

// 选择分类
const selectCategory = (categoryId) => {
selectedCategory.value = categoryId;
}

// 过滤文章
const filteredArticles = computed(() => {
let result = articles.value

// 按分类过滤
if (selectedCategory.value !== 'all') {
    result = result.filter(article => article.category === selectedCategory.value)
}

// 搜索过滤
if (searchQuery.value) {
    const query = searchQuery.value.toLowerCase();
    result = result.filter(article => 
    article.title.toLowerCase().includes(query) || 
    article.excerpt.toLowerCase().includes(query) ||
    article.author.toLowerCase().includes(query)
    )
}

return result
})
</script>

<style scoped>
.blog-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
  color: #212529;
  line-height: 1.6;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.blog-header {
  background: linear-gradient(120deg, #4361ee, #3f37c9);
  color: white;
  padding: 20px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.home-icon {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-right: 20px;
    transition: var(--transition);
}

.home-icon i {
    font-size: 1.8rem;
    color: white;
    background: rgba(255, 255, 255, 0.2);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition);
}

.home-icon:hover i {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.8rem;
  font-weight: 700;
}

.logo i {
  color: #4895ef;
  background: white;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.search-container {
  position: relative;
  width: 50%;
  max-width: 500px;
}

.search-container input {
  width: 100%;
  padding: 14px 20px;
  padding-left: 50px;
  border: none;
  border-radius: 50px;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.search-container input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.3);
}

.search-container i {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: #6c757d;
  font-size: 1.2rem;
}

.blog-main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.hero {
  text-align: center;
  padding: 60px 0 40px;
}

.hero h1 {
  font-size: 2.8rem;
  margin-bottom: 20px;
  background: linear-gradient(to right, #4361ee, #4895ef);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  font-size: 1.2rem;
  max-width: 700px;
  margin: 0 auto 30px;
  color: #6c757d;
}

.categories {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 15px;
  margin: 30px 0;
}

.category-btn {
  padding: 10px 24px;
  border: none;
  border-radius: 50px;
  background: white;
  color: #6c757d;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.category-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
}

.category-btn.active {
  background: linear-gradient(to right, #4361ee, #4895ef);
  color: white;
}

.content {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 30px;
  margin-top: 30px;
}

.blog-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.blog-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
}

.card-image {
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 2.5rem;
}

.card-content {
  padding: 25px;
}

.card-category {
  display: inline-block;
  background: #e9ecef;
  color: #4361ee;
  padding: 5px 12px;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 15px;
}

.card-title {
  font-size: 1.4rem;
  margin-bottom: 12px;
  color: #212529;
}

.card-excerpt {
  color: #6c757d;
  margin-bottom: 20px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  color: #6c757d;
  font-size: 0.9rem;
  padding-top: 15px;
  border-top: 1px solid #e9ecef;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
}

.empty-state i {
  font-size: 4rem;
  color: #e9ecef;
  margin-bottom: 20px;
}

.empty-state h3 {
  font-size: 1.8rem;
  margin-bottom: 15px;
  color: #6c757d;
}

.empty-state p {
  color: #6c757d;
  max-width: 500px;
  margin: 0 auto;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 40px;
  flex-wrap: wrap;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 25px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  min-width: 200px;
}

.stat-card i {
  font-size: 2.5rem;
  color: #4361ee;
  margin-bottom: 15px;
}

.stat-card .number {
  font-size: 2.2rem;
  font-weight: 700;
  color: #3f37c9;
  margin-bottom: 5px;
}

.stat-card .label {
  color: #6c757d;
  font-size: 1rem;
}

.blog-footer {
  text-align: center;
  padding: 30px 0;
  margin-top: 60px;
  color: #6c757d;
  border-top: 1px solid #e9ecef;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 20px;
  }
  
  .search-container {
    width: 100%;
  }
  
  .hero h1 {
    font-size: 2.2rem;
  }
  
  .content {
    grid-template-columns: 1fr;
  }
  
  .stat-card {
    min-width: 150px;
  }
}
</style>